package com.yourname.action;

import com.yourname.entity.Student;
import com.yourname.entity.Teacher;
import com.yourname.menu.FunctionMenu;
import com.yourname.store.DataStore;

import java.util.Scanner;

public class LoginAction {
    private static String current;//存储当前登录的用户（学生或者老师）的工号或者学号
    private static String loginTag="";//登录的身份标识，用于判断登陆后展示哪种菜单。
    /**
     * 学生登录
     */
    public static void studentLogin(){
        System.out.println("""
                请输入用户名和密码，中间用短横杠分割
                """);
        Scanner scanner=new Scanner(System.in);
        String next = scanner.next();
        String[] split = next.split("-");
        Student student = DataStore.getStudent(split[0]);
        if (student!=null){
            if (student.getPassword().equals(split[1])){
                System.out.println("登录成功");
                loginTag="student";
                current=student.getId();
                FunctionMenu.studentFunctionsMenu();
            }else{
                System.out.println("密码错误");
            }
        }
    }
    /**
     * 教师登录
     */
    public static void teacherLogin(){
        System.out.println("""
                请输入用户名和密码，中间用短横杠分割
                """);
        Scanner scanner=new Scanner(System.in);
        String next = scanner.next();
        String[] split = next.split("-");
        Teacher teacher = DataStore.getTeacher(split[0]);
        if (teacher!=null){
            if (teacher.getPassword().equals(split[1])){
                System.out.println("登录成功");
                loginTag="teacher";
                current=teacher.getId();
                FunctionMenu.teacherFunctionsMenu();
            }else{
                System.out.println("密码错误");
            }
        }
    }

    public static String getCurrent() {
        return current;
    }
    public static String getLoginTag() {
        return loginTag;
    }
}
